home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-13 | 76.3 KB | 2,939 lines | [TEXT/MPS ] |
- /*------------------------------------------------------------------------------
-
- File: TextEditorEvents.cpp
-
- Description: TextEditor's event handling protocol methods.
-
- Written by: Steve Smith
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
- ------------------------------------------------------------------------------*/
-
- // Notification that this is a SOM source file
- #define SampleCode_TextEditor_Class_Prototypes
- // define underscore (_) field names
- #define VARIABLE_MACROS
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (e.g. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- TextEditor Includes
-
- #ifndef SOM_SampleCode_TextEditor_xih
- #include "TextEditor.xih"
- #endif
-
- #ifndef _TEXTEDITORDEF_
- #include "TextEditorDef.h"
- #endif
-
- #ifndef _TEXTEDITORUTILS_
- #include "TextEditorUtils.h"
- #endif
-
- #ifndef _TEXTEDITORGLOBALS_
- #include "TextEditorGlobals.h"
- #endif
-
- #ifndef _TEXTEDITORPREFS_
- #include "TextEditorPrefs.h"
- #endif
-
- #ifndef _TEXTEDITORSETTINGS_
- #include "TextEditorSettings.h"
- #endif
-
- #ifndef _STDTEXTPROPERTIES_
- #include "StdTextProps.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODTranslation_h
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _DLOGUTIL_
- #include <DlogUtil.h>
- #endif
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- // -- Macintosh Includes --
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- // -- Textension Includes --
-
- #ifndef _Textension_
- #include "Textension.h"
- #endif
-
- #ifndef _TSMTextension_
- #include "TSMTextension.h"
- #endif
-
- #ifndef _QDTextRun_
- #include "QDTextRun.h"
- #endif
-
- #ifndef _Display_
- #include "Display.h"
- #endif
-
- #ifndef _AdvancedRuler_
- #include "AdvancedRuler.h"
- #endif
-
- #ifndef _RunObject_
- #include "RunObject.h"
- #endif
-
- #ifndef _LinkedFrames_
- #include "LinkedFrames.h"
- #endif
-
- #ifndef _AttrObject_
- #include "AttrObject.h"
- #endif
-
- // -- ScriptRunner Includes --
-
- #ifndef SOM_PaletteExt_xh
- #include "PaletteExt.xh"
- #endif
-
- #ifndef _SCRIPTRUNNERSUPPORT_
- #include "ScriptRunnerSupport.h"
- #endif
-
-
- //==============================================================================
- // Typedefs
- //==============================================================================
-
- struct DragData
- {
- TOffsetRange dropPoint;
- ODSShort acceptable;
- ODFacet* originator;
- };
-
- //==============================================================================
- #pragma mark • Utility functions •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Function: XorInsertionPoint
- //------------------------------------------------------------------------------
-
- static void XorInsertionPoint( CTextension* textension, TOffsetRange& range )
- {
- if ( range.Start() != -1 )
- {
- short height;
- Point caret = textension->CharToPoint(range.rangeStart, &height);
-
- MoveTo(caret.h, caret.v);
- PenPat(&ODQDGlobals.black);
- PenMode(patXor);
-
- Line(0, height);
- PenNormal();
- }
- }
-
- //==============================================================================
- #pragma mark • Menus •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: AdjustMenus
- // Origin: ODPart
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__AdjustMenus
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","AdjustMenus");
-
- SOM_TRY
-
- // The menubar object always calls the root part's AdjustMenus method before
- // calling the menu focus owner's. Because of this, we need to validate the
- // menubar in the case where we are the root part.
- if ( frame->IsRoot(ev) )
- {
- // We are required to re-validate the menubar before displaying it because
- // any part can/could swap the base menubar at any time.
- if ( !gGlobals->fMenuBar->IsValid(ev) )
- somSelf->LoadMenus(ev);
- }
-
- TRY
- somSelf->AdjustEditMenu(ev, frame);
- // Adjust the Edit menu.
-
- somSelf->AdjustTextEditorMenus(ev, frame);
- // Adjust our menus
-
- somSelf->AdjustDynamicMenuItems(ev, frame);
- // Change the text of the menu items that are dynamic (e.g. Show/Hide)
-
- CATCH_ALL
- // Consume the exception and prevent it from being propogated.
- ENDTRY
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: AdjustEditMenu
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__AdjustEditMenu
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","AdjustEditMenu");
-
- SOM_TRY
-
- TOffsetRange curSelectionRange;
- ODBoolean realSelection;
-
- // Edit Menu
-
- _fTextension->GetSelectionRange(&curSelectionRange);
- realSelection = ( curSelectionRange.Start() < curSelectionRange.End() );
-
- // If the user has made a selection, enable the Edit commands.
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandCopy, realSelection);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandCut, !_fReadOnlyStorage && realSelection);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandClear, !_fReadOnlyStorage && realSelection);
-
- // If the is any content, enable this command.
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandSelectAll,
- (ODBoolean) _fTextension->CountCharsBytes());
-
- TRY
- ODSession* session = ODGetSession(ev, frame);
-
- ODBoolean mustTranslate = kODFalse;
- ODBoolean validData = kODFalse;
-
- if ( session->GetArbitrator(ev)->RequestFocus(ev, gGlobals->fClipboardFocus, frame) )
- {
- ODStorageUnit* clipboardSU = ODGetSession(ev, somSelf)->GetClipboard(ev)
- ->GetContentStorageUnit(ev);
-
- // If there is any palatable content on the clipboard, enable the paste
- // and paste as... commands.
- mustTranslate = kODFalse;
- validData = somSelf->HasValidData(ev, clipboardSU, &mustTranslate);
-
- session->GetArbitrator(ev)->RelinquishFocus(ev, gGlobals->fClipboardFocus, frame);
- }
-
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPaste,
- !_fReadOnlyStorage && validData && !mustTranslate);
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPasteAs,
- !_fReadOnlyStorage && validData && mustTranslate);
- CATCH_ALL
- // It is unfortunate, but not fatal, to not have the Paste menu item
- // enable properly. Therefore, we consume the error.
- ENDTRY
-
- // Enable the "View As Window" command if the frame is not the root
- // frame of the window.
- // gGlobals->fMenuBar->EnableCommand(ev, kODCommandViewAsWin, !frame->IsRoot(ev));
- // Currently, we don't support View In Window, so dim that item.
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandViewAsWin, kODFalse);
-
- // Always enable "Preferences".
- gGlobals->fMenuBar->EnableCommand(ev, kODCommandPreferences, kODTrue);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: AdjustTextEditorMenus
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__AdjustTextEditorMenus
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","AdjustTextEditorMenus");
-
- SOM_TRY
-
- ODMenuBar* mbar = gGlobals->fMenuBar;
-
- // Font, Size, Style Menus
-
- const CRunObject* continuousRun = _fTextension->GetContinuousRun();
- ODSLong value;
-
- // Font.
- MenuHandle fontMenu = mbar->GetMenu(ev, kFontMenuID);
-
- for (int i=1; i <= CountMItems(fontMenu); i++)
- {
- mbar->CheckCommand(ev, mbar->GetCommand(ev, kFontMenuID, i), kODFalse);
- }
-
- if ( continuousRun->GetAttributeValue(kFontAttr, &value) )
- {
- value = value >> 16;
-
- if ( value == applFont )
- {
- long result = GetScriptVariable(smSystemScript, smScriptAppFondSize);
- value = HiWord(result); // hi-word contains font number.
- }
-
- ODCommandID command = kBaseFontCmdID + value;
-
- mbar->CheckCommand(ev, kBaseFontCmdID+value, kODTrue);
-
- somSelf->RealFontSizeMenu(ev, value);
- }
-
- // Size.
- if ( continuousRun->GetAttributeValue(kFontSizeAttr, &value) )
- value = value >> 16;
- else
- value = -1;
-
- mbar->CheckCommand(ev, kBaseFontSizeCmdID + 9, (value == 9));
- mbar->CheckCommand(ev, kBaseFontSizeCmdID + 10, (value == 10));
- mbar->CheckCommand(ev, kBaseFontSizeCmdID + 12, (value == 12));
- mbar->CheckCommand(ev, kBaseFontSizeCmdID + 14, (value == 14));
- mbar->CheckCommand(ev, kBaseFontSizeCmdID + 18, (value == 18));
- mbar->CheckCommand(ev, kBaseFontSizeCmdID + 24, (value == 24));
- mbar->CheckCommand(ev, kBaseFontSizeCmdID + 36, (value == 36));
- mbar->CheckCommand(ev, kBaseFontSizeCmdID + 48, (value == 48));
- mbar->CheckCommand(ev, kBaseFontSizeCmdID + 72, (value == 72));
-
- // Set up the checkmark on the "Other" size menu item.
- switch ((ODSShort) value)
- {
- case -1:
- case 9:
- case 10:
- case 12:
- case 14:
- case 18:
- case 24:
- case 36:
- case 48:
- case 72:
- mbar->CheckCommand(ev, kOtherFontSizeCmdID, kODFalse);
- break;
-
- default:
- mbar->CheckCommand(ev, kOtherFontSizeCmdID, kODTrue);
- }
-
- // Style.
- if ( continuousRun->GetAttributeValue(kFaceAttr, &value) )
- {
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + normal, (value == normal));
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + bold, (value & bold) != 0);
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + italic, (value & italic) != 0);
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + underline, (value & underline) != 0);
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + outline, (value & outline) != 0);
- }
- else
- {
- // There is more than one run of differently-styled text in the current
- // selection. For now, just uncheck everything.
-
- // The proper user interface for this would be do walk the runs and mark
- // each style that was found in all runs with a check mark and any other
- // style that was found in only SOME of the runs with a dash character.
-
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + normal, kODFalse);
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + bold, kODFalse);
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + italic, kODFalse);
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + underline, kODFalse);
- mbar->CheckCommand(ev, kBaseFontStyleCmdID + outline, kODFalse);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: AdjustDynamicMenuItems
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__AdjustDynamicMenuItems
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","AdjustDynamicMenuItems");
-
- SOM_TRY
-
- TRY
- ODArbitrator* arbitrator = ODGetSession(ev, somSelf)->GetArbitrator(ev);
- TempODFrame menuOwner = arbitrator->AcquireFocusOwner(ev, gGlobals->fMenuFocus);
-
- // There is no need to load a resource, create an ODIText object, set the menubar,
- // and cleanup, if we don't own the menu focus.
- if ( ODObjectsAreEqual(ev, frame, menuOwner) )
- {
- // Change the "About…" item text for our part.
- SetMenuCommandIndString(ev, kODCommandAbout, kRuntimeStringsID, kAboutTextStrIndex);
-
- // Change the "Preferences" item text for our part.
- SetMenuCommandIndString(ev, kODCommandPreferences, kRuntimeStringsID, kPreferencesStrIndex);
-
- gGlobals->fMenuBar->EnableCommand(ev, kShowHideRulerCmdID, kODFalse);
- /*
- if ( _fRulerPalette != kODNULLID )
- SetMenuCommandIndString(ev, kShowHideRulerCmdID, kRuntimeStringsID, kHideRulerStrIndex);
- else
- SetMenuCommandIndString(ev, kShowHideRulerCmdID, kRuntimeStringsID, kShowRulerStrIndex);
- */
-
- // Set up the items in the tools menu.
-
- somSelf->UpdateScriptRunnerState(ev);
- SetMenuCommandIndString(ev, kToggleScriptRunnerCmdID, kRuntimeStringsID,
- _fIsScriptRunnerOn ? kHideScriptRunnerStrIndex
- : kShowScriptRunnerStrIndex);
-
- Boolean installed = (_fScriptPaletteExt != kODNULL)
- || IsScriptRunnerInstalled(ev, ODGetSession(ev, _fSelf));
-
- gGlobals->fMenuBar->EnableCommand(ev, kToggleScriptRunnerCmdID,
- !_fReadOnlyStorage && installed);
-
- // Set up Settings menu item.
-
- gGlobals->fMenuBar->EnableCommand(ev, kSettingsCmdID,
- !_fReadOnlyStorage);
- }
- CATCH_ALL
- ENDTRY
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //==============================================================================
- #pragma mark • Event Handling •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: HandleEvent
- // Origin: ODPart
- //------------------------------------------------------------------------------
- #pragma segment TextEditorEvents
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__HandleEvent
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODEventData* event,
- ODFrame* frame,
- ODFacet* facet,
- ODEventInfo* eventInfo
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","HandleEvent");
-
- ODBoolean eventHandled = kODFalse;
-
- SOM_TRY
-
- // Event handling is basically the same as standard Macintosh applications,
- // except that the events have been renamed for cross-platform compatability.
-
- switch ( event->what )
- {
- case kODEvtMouseDown:
- case kODEvtMouseUp:
- case kODEvtBGMouseDown:
- eventHandled = somSelf->HandleMouseEvent(ev, event, facet, eventInfo);
- break;
-
- case kODEvtMenu:
- eventHandled = somSelf->HandleMenuEvent(ev, event, frame);
- break;
-
- case kODEvtActivate:
- // We are being notified that a window we are displayed in has
- // just been activated/deactivated (hilighted/unhilighted).
- somSelf->WindowActivating(ev, frame, (event->modifiers & activeFlag));
- eventHandled = kODTrue;
- break;
-
- case kODEvtAutoKey:
- case kODEvtKeyDown:
- eventHandled = somSelf->HandleKeyboardEvent(ev, event, frame);
- break;
-
- case kODEvtMouseEnter:
- somSelf->MouseEnter(ev, facet, &(eventInfo->where));
- eventHandled = kODTrue;
- break;
-
- case kODEvtMouseWithin:
- somSelf->MouseWithin(ev, facet, &(eventInfo->where));
- eventHandled = kODTrue;
- break;
-
- case kODEvtMouseLeave:
- somSelf->MouseLeave(ev, facet);
- eventHandled = kODTrue;
- break;
-
- case kODEvtOS:
- somSelf->WindowActivating(ev, frame, (event->message & resumeFlag));
- // We are being notified that a window we are display in has
- // just been suspened/resumed.
- eventHandled = kODTrue;
- break;
-
- case kODEvtWindow:
- eventHandled = somSelf->HandleWindowEvent(ev, event, frame);
- break;
-
- // Other events a part might handle:
- case kODEvtNull:
- somSelf->DoIdle(ev, frame);
- break;
-
- case kODEvtMouseDownBorder:
- case kODEvtKeyUp:
- case kODEvtDisk:
- default:
- break;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return eventHandled;
- }
-
- //------------------------------------------------------------------------------
- // Method: HandleMenuEvent
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__HandleMenuEvent
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODEventData* event,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","HandleMenuEvent");
-
- SOM_TRY
-
- ODUShort menu = HiWord(event->message);
- ODUShort item = LoWord(event->message);
- ODID command = gGlobals->fMenuBar->GetCommand(ev, menu, item);
-
- switch( command ) {
-
- case kODCommandAbout:
- somSelf->DoAboutBox(ev, frame);
- break;
-
- case kODCommandViewAsWin:
- somSelf->Open(ev, frame);
- break;
-
- case kODCommandCut:
- somSelf->DoCut(ev, frame);
- break;
-
- case kODCommandCopy:
- somSelf->DoCopy(ev, frame);
- break;
-
- case kODCommandPaste:
- somSelf->DoPaste(ev, frame);
- break;
-
- case kODCommandPasteAs:
- somSelf->DoPasteAs(ev, frame);
- break;
-
- case kODCommandClear:
- somSelf->DoClear(ev, frame);
- break;
-
- case kODCommandSelectAll:
- somSelf->DoSelectAll(ev, frame);
- break;
-
- case kODCommandPageSetup:
- somSelf->DoPageSetup(ev, frame);
- break;
-
- case kODCommandPrint:
- somSelf->DoPrint(ev, frame);
- break;
-
- case kODCommandPreferences:
- somSelf->DoPreferences(ev, frame);
- break;
-
- case kShowHideRulerCmdID:
- somSelf->ShowHideRuler(ev, frame);
- break;
-
- case kSettingsCmdID:
- somSelf->DoSettings(ev, frame);
- break;
-
- case kToggleScriptRunnerCmdID:
- if ( _fScriptPaletteExt == kODNULL
- && IsScriptRunnerInstalled(ev, ODGetSession(ev, _fSelf)) )
- {
- _fScriptPaletteExt = AcquireScriptRunner(ev, ODGetDraft(ev, somSelf));
- _fScriptPaletteExt->SetClient(ev, _fSelf);
- }
-
- if ( _fScriptPaletteExt )
- {
- if ( _fIsScriptRunnerOn )
- {
- _fScriptPaletteExt->Hide(ev);
- ODReleaseObject(ev, _fScriptPaletteExt);
- _fIsScriptRunnerHidden = kODFalse;
- }
- else
- {
- _fScriptPaletteExt->Show(ev);
- _fIsScriptRunnerHidden = kODFalse;
- }
- }
-
- _fIsScriptRunnerOn = !_fIsScriptRunnerOn;
-
- if ( !_fReadOnlyStorage )
- somSelf->SetDirty(ev);
- break;
-
- default:
- return somSelf->DoTextStyling(ev, frame, command);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // Method: HandleWindowEvent
- // Origin: TextEditor
- //
- // Description: This method is called by the part to handle user event in a
- // window.
- //
- // The part never actually destoys windows when they are closed by
- // the user; they are merely hidden until the document is closed.
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__HandleWindowEvent
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODEventData* event,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","HandleWindowEvent");
-
- ODBoolean handled = kODFalse;
-
- SOM_TRY
-
- // This function is unneeded. It was left in for possible future
- // use for a ruler window.
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return handled;
- }
-
-
- //------------------------------------------------------------------------------
- // Method: HandleMouseEvent
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__HandleMouseEvent
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODEventData* event,
- ODFacet* facet,
- ODEventInfo* eventInfo
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","HandleMouseEvent");
-
- SOM_TRY
-
- ODFrame* frame = facet->GetFrame(ev);
-
- // If the facet parameter is invalid, the mouse up occurred outside the
- // bounds of a Modal window, otherwise it should be treated normally.
-
- if (facet != kODNULL)
- {
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- // Activate the window and frame unless it's a mouse down in an
- // inactive window because it may become a background drag operation.
-
- if ( event->what != kODEvtBGMouseDown )
- if ( somSelf->Activate(ev, facet) == kODFalse )
- return kODFalse;
-
- if ( event->what == kODEvtMouseDown ||
- event->what == kODEvtBGMouseDown )
- {
- Point where;
-
- // Get the localized mouse coordinates from the Event Info.
- where.h = FixedToInt(eventInfo->where.x);
- where.v = FixedToInt(eventInfo->where.y);
-
- // Handle the mouse down event.
- somSelf->DoMouseEvent(ev, facet, &where, event);
- }
- }
- // For now, the ruler is "dumb". We could allow the user to set tabs
- // on the ruler.
- else if ( frame->GetPresentation(ev) == gGlobals->fRulerPresentation )
- {
- somSelf->HandleRulerMouseEvent(ev, event, facet, eventInfo);
- }
- }
- else
- {
- // User clicked outside the bounds of a Modal window.
- SysBeep(1);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // Method: HandleMouseEvent
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__HandleRulerMouseEvent
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODEventData* event,
- ODFacet* facet,
- ODEventInfo* eventInfo
- )
- {
- // SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","HandleRulerMouseEvent");
-
- return kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // Method: HandleKeyboardEvent
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__HandleKeyboardEvent
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODEventData* event,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","HandleKeyboardEvent");
-
- ODBoolean result = kODFalse;
-
- SOM_TRY
-
- if ( event->modifiers & cmdKey )
- {
- result = kODFalse;
- }
- else
- {
- if ( _fReadOnlyStorage && KeyCausesModification(event) )
- return kODFalse;
-
- TKeyDownFlags flags;
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- ODFacet* activeFacet = frameInfo->GetActiveFacet();
-
- // •• Need to handle page-up, page-down, home, end, etc.
-
- {
- CFocus initiateDrawing(ev, activeFacet);
- flags = _fTextension->KeyDown(*(EventRecord*) event);
- }
-
- if ( flags & kKeyDownHandled )
- {
- // Certain keys, like arrows, shouldn't make the part dirty.
- if ( !(flags & kArrowKey) )
- somSelf->HandleChange(ev);
-
- somSelf->MakeSelectionVisible(ev, frame);
-
- // <new method>
- // get frames
- // if ( frames->IsLastFrameOverflow() )
- // {
- // request grow vertically
- // if not ok
- // request grow horizontally
- // if not ok
- // add new frame with same width, just below
- //
- }
-
- result = ( flags & kKeyDownHandled );
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return result;
- }
-
- //==============================================================================
- #pragma mark • Mouse Tracking •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: MouseEnter
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__MouseEnter
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet,
- ODPoint* where
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","MouseEnter");
-
- SOM_TRY
-
- somSelf->MouseWithin(ev, facet, where);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //------------------------------------------------------------------------------
- // Method: MouseWithin
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__MouseWithin
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet,
- ODPoint* where
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","MouseWithin");
-
- SOM_TRY
-
- Point mouse;
- ODFrame* frame = facet->GetFrame(ev);
-
- mouse.h = FixedToInt(where->x);
- mouse.v = FixedToInt(where->y);
-
- if ( frame->GetPresentation(ev) == gGlobals->fMainPresentation )
- {
- // optimization opportunity: should try to calculate this less often.
- somSelf->CalcSelectionRgn(ev, facet);
-
- if ( PtInRgn(mouse, (RgnHandle) _fSelectionRgn) )
- {
- SetCursor(&ODQDGlobals.arrow);
- }
- else if ( frame->IsRoot(ev) &&
- ( PtInRect(mouse, &((**_fVScrollbar).contrlRect)) ||
- PtInRect(mouse, &((**_fHScrollbar).contrlRect)) ) )
- {
- SetCursor(&ODQDGlobals.arrow);
- }
- else
- {
- SetCursor(*GetCursor(iBeamCursor));
- }
- }
- else
- {
- SetCursor(&ODQDGlobals.arrow);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: MouseLeave
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__MouseLeave
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","MouseLeave");
-
- SetCursor(&ODQDGlobals.arrow);
- }
-
- //==============================================================================
- #pragma mark • Drag and Drop •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: DragEnter
- // Origin: ODPart
- //------------------------------------------------------------------------------
-
- SOM_Scope ODDragResult
- SOMLINK TextEditor__DragEnter
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODDragItemIterator* dragInfo,
- ODFacet* facet,
- ODPoint* where
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DragEnter");
-
- ODDragResult dragOK = kODFalse;
-
- SOM_TRY
-
- // Don't allow dropping in a read only part.
- if ( _fReadOnlyStorage )
- return kODFalse;
-
- // Don't allow dropping in icon or thumbnail views.
- if ( facet->GetFrame(ev)->GetViewType(ev) != gGlobals->fFrameView )
- return kODFalse;
-
- // If we haven't set up a drag tracking structure yet, do so now.
- if ( _fDragData == kODNULL)
- {
- TOffsetRange curSelectionRange((long) -1, (long) 0);
-
- //_fTextension->GetSelectionRange(&curSelectionRange);
-
- _fDragData = new DragData;
-
- _fDragData->dropPoint = curSelectionRange;
- _fDragData->acceptable = kUndefined;
- _fDragData->originator = kODNULL;
- }
-
- // If we are dragging our own data in one of our own facets, we know
- // the data is valid; otherwise, we must check.
- if ( _fDragData->originator )
- {
- ODFacet* sourceFacet = _fDragData->originator;
- TempODPart sourcePart = sourceFacet->GetFrame(ev)->AcquirePart(ev);
- TempODPart destPart = facet->GetFrame(ev)->AcquirePart(ev);
-
- if ( ODObjectsAreEqual(ev, sourcePart, destPart) )
- dragOK = kODTrue;
- }
-
- // If the above test didn't give us the info we needed, validate the contents
- // of the drag.
- if ( !dragOK )
- {
- for ( ODStorageUnit* dragSU = dragInfo->First(ev); dragSU;
- dragSU = dragInfo->Next(ev) )
- {
- ODBoolean mustTranslate = kODFalse;
- if (somSelf->HasValidData(ev, dragSU, &mustTranslate))
- dragOK = kODTrue;
- }
- }
-
- // Use the arrow cursor for drop tracking
- SetCursor(&ODQDGlobals.arrow);
-
- // Set the drag validity and corresponding cursor.
- if ( dragOK )
- {
- // The data in the D&D storage unit is valid data
- _fDragData->acceptable = kODTrue;
-
- // Get the toolbox reference for the current drag operation.
- ODDragAndDrop* dad = ODGetSession(ev, somSelf)->GetDragAndDrop(ev);
-
- // Show the Mac Drag Mgr highlighting in our frame.
- if ( !(dad->GetDragAttributes(ev) & kODDragIsInSourceFrame) )
- {
- CFocus initiateDrawing(ev, facet);
-
- // Calculate a region to be used for dragging feedback.
- CFrames* frames = _fTextension->GetFramesHandler();
- Rect textRect;
- frames->GetTextBounds(0, &textRect);
- if ( facet->GetFrame(ev)->IsRoot(ev) )
- InsetRect(&textRect, -6, -6);
-
- RgnHandle dragHilite = ODNewRgn();
- RectRgn(dragHilite, &textRect);
-
- ShowDragHilite(dad->GetDragReference(ev), dragHilite, true);
-
- ODDisposeHandle((ODHandle) dragHilite);
- }
- }
-
- SOM_CATCH_ALL
-
- dragOK = kODFalse;
-
- SOM_ENDTRY
-
- return dragOK;
- }
-
- //------------------------------------------------------------------------------
- // Method: DragWithin
- // Origin: ODPart
- //------------------------------------------------------------------------------
-
- SOM_Scope ODDragResult
- SOMLINK TextEditor__DragWithin
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODDragItemIterator* dragInfo,
- ODFacet* facet,
- ODPoint* where
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DragWithin");
-
- ODBoolean result = kODTrue;
-
- SOM_TRY
-
- // Don't allow dropping in a read only part.
- if ( _fReadOnlyStorage )
- return kODFalse;
-
- // Don't allow dropping in icon or thumbnail views.
- if ( facet->GetFrame(ev)->GetViewType(ev) != gGlobals->fFrameView )
- return kODFalse;
-
- // If the acceptabability is not yet defined, call DragEnter to assess it.
-
- if ( _fDragData->acceptable == kUndefined )
- somSelf->DragEnter(ev, dragInfo, facet, where);
-
- // If the drag data is unacceptable, just exit.
- if ( !_fDragData->acceptable )
- {
- result = kODFalse;
- }
- else
- {
- // Otherwise, track the mouse with the insertion point.
-
- CFocus initiateDrawing(ev, facet);
-
- Point pt;
- pt.v = FixedToInt(where->y);
- pt.h = FixedToInt(where->x);
-
- TOffsetRange curDropRange;
- ODBoolean outsideFrame;
- ODBoolean outsideLine;
-
- const CRunObject* run = _fTextension->PointToChar(pt, &curDropRange,
- &outsideFrame, &outsideLine);
-
- if ( curDropRange.Start() != _fDragData->dropPoint.Start() )
- {
- // Erase old insertion point.
- XorInsertionPoint(_fTextension, _fDragData->dropPoint);
-
- // Check the new drop location.
-
- TOffsetRange curSelectionRange;
- _fTextension->GetSelectionRange(&curSelectionRange);
-
- // Determine if the drop is in the originating part.
- ODBoolean isInOriginatingPart = kODFalse;
- if ( _fDragData->originator )
- {
- TempODPart sourcePart = _fDragData->originator->GetFrame(ev)->AcquirePart(ev);
-
- if ( ODObjectsAreEqual(ev, sourcePart, _fSelf) )
- isInOriginatingPart = kODTrue;
- }
-
- if ( isInOriginatingPart &&
- curDropRange.Start() >= curSelectionRange.Start() &&
- curDropRange.Start() <= curSelectionRange.End() )
- {
- // We're in the selection range, so don't draw a caret.
-
- // Set rangeStart to -1 to flag that it is not being drawn.
- _fDragData->dropPoint.rangeStart = -1;
- }
- else
- {
- // Draw new insertion point.
- _fDragData->dropPoint = curDropRange;
- XorInsertionPoint(_fTextension, _fDragData->dropPoint);
- }
- }
- }
-
- SOM_CATCH_ALL
-
- result = kODFalse;
-
- SOM_ENDTRY
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // Method: DragLeave
- // Origin: ODPart
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DragLeave
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet,
- ODPoint* where
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DragLeave");
-
- SOM_TRY
-
- // Don't allow dropping in a read only part.
- if ( _fReadOnlyStorage )
- return;
-
- // Don't allow dropping in icon or thumbnail views.
- if ( facet->GetFrame(ev)->GetViewType(ev) != gGlobals->fFrameView )
- return;
-
- DragReference dragRef = ODGetSession(ev, somSelf)->GetDragAndDrop(ev)
- ->GetDragReference(ev);
-
- CFocus initiateDrawing(ev, facet);
-
- // Hide the Mac Drag Mgr highlighting.
- HideDragHilite(dragRef);
-
- // Erase the last insertion pt.
- XorInsertionPoint(_fTextension, _fDragData->dropPoint);
-
- // Set rangeStart to -1 to flag that it is not being drawn.
- _fDragData->dropPoint.rangeStart = -1;
-
- // If the drag didn't originate with us, we clean up the temporary
- // drag structure here.
-
- if ( _fDragData->originator == kODNULL )
- {
- ODDeleteObject(_fDragData);
- _fDragData = kODNULL;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: Drop
- // Origin: ODPart
- //------------------------------------------------------------------------------
-
- SOM_Scope ODDropResult
- SOMLINK TextEditor__Drop
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODDragItemIterator* dropInfo,
- ODFacet* facet,
- ODPoint* where
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","Drop");
-
- ODDropResult result = kODDropFail;
-
- SOM_TRY
-
- if ( _fReadOnlyStorage || !_fDragData->acceptable )
- return kODDropFail;
-
- // Don't allow dropping in icon or thumbnail views.
- if ( facet->GetFrame(ev)->GetViewType(ev) != gGlobals->fFrameView )
- return kODDropFail;
-
- // Prepare the drawing environment.
- CFocus initiateDrawing(ev, facet);
-
- ODFrame* frame = facet->GetFrame(ev);
- ODSession* session = ODGetSession(ev, somSelf);
-
- ODULong dragAttributes = session->GetDragAndDrop(ev)->GetDragAttributes(ev);
-
- // Erase last insertion point.
- XorInsertionPoint(_fTextension, _fDragData->dropPoint);
-
- DragReference dragRef = session->GetDragAndDrop(ev)->GetDragReference(ev);
-
- TOffsetRange curSelectionRange;
- _fTextension->GetSelectionRange(&curSelectionRange);
-
- HideDragHilite(dragRef);
-
- if ( _fDragData->dropPoint.Start() == -1 ||
- ((dragAttributes & kODDropIsInSourceFrame) &&
- _fDragData->dropPoint.Start() >= curSelectionRange.Start() &&
- _fDragData->dropPoint.Start() <= curSelectionRange.End()) )
- {
- // Item is being dropped inside the original selection
-
- result = kODDropFail;
- }
- else
- {
- // Determine the nature of the drag (copy vs. move).
- if ( dragAttributes & kODDropIsMove )
- result = kODDropMove;
- else if ( dragAttributes & kODDropIsCopy )
- result = kODDropCopy;
- else if ( dragAttributes & kODDropIsPasteAs )
- result = kODDropMove; // Since we don't handle Paste As.
-
- ODBoolean textensionInactive = kODFalse;
- if ( !facet->GetWindow(ev)->IsActive(ev) )
- {
- textensionInactive = kODTrue;
- _fTextension->Activate(kODTrue);
- }
-
- // Suspend drawing until all mangling is complete.
- CTextensionDisplay* display = _fTextension->GetDisplayHandler();
- display->DisableDrawing();
-
- TRY
- if ( result == kODDropMove && (dragAttributes & kODDragIsInSourceFrame) )
- {
- // The item is being dropped in the source frame, thus signifying
- // a "move". So we first remove the original data.
- somSelf->DoClear(ev, frame);
-
- // Adjust the drop range. Removing the old "current" selection may cause
- // things to move.
- if ( _fDragData->dropPoint.Start() >= curSelectionRange.End() )
- {
- long newStart = _fDragData->dropPoint.Start() -
- (curSelectionRange.End() - curSelectionRange.Start());
-
- _fDragData->dropPoint.Set(newStart, newStart, false, true);
- }
- }
-
- // We use -1 to denote an empty document but Textension doesn't like
- // negative numbers. So I am setting the "selection" range to a valid
- // value.
- if ( _fDragData->dropPoint.Start() == -1 )
- _fDragData->dropPoint.Set(0L, 1L, false, true);
-
- // Read in the data from each of the Drag & Drop StorageUnits.
- for (ODStorageUnit* dragSU = dropInfo->First(ev); dragSU; dragSU = dropInfo->Next(ev))
- {
- // If its something we can internalize, do so.
- if ( dragSU->Exists(ev, kODPropContents, kTextEditorKind, 0)
- || dragSU->Exists(ev, kODPropContents, gGlobals->fScrapTextValue, 0)
- || dragSU->Exists(ev, kODPropContents, gGlobals->fTextFileValue, 0) )
- {
- ODULong bytesRead = somSelf->InternalizeContent(ev, dragSU,
- &_fDragData->dropPoint);
-
- if ( bytesRead > 0 )
- somSelf->HandleChange(ev);
- }
- else
- // Otherwise, translate.
- {
- dragSU->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 1, kODPosUndefined);
- TempODValueType foreignDataType = dragSU->GetType(ev);
-
- if ( session->GetTranslation(ev)->CanTranslate(ev, foreignDataType) == kODCanTranslate )
- {
- ODBoolean successful = somSelf->TranslateForeignData(ev, dragSU);
-
- if ( successful )
- somSelf->HandleChange(ev);
- }
- }
-
- // Set up the selection to include the just-dragged-in area.
- {
- TOffsetRange dragEnd;
- _fTextension->GetSelectionRange(&dragEnd);
-
- long newStart = _fDragData->dropPoint.Start();
- long newEnd = dragEnd.Start();
-
- _fDragData->dropPoint.Set(newStart, newEnd, false, true);
- _fTextension->SetSelectionRange(_fDragData->dropPoint);
- }
- }
- CATCH_ALL
- // Done mangling the text. Force update.
- display->EnableDrawing();
- display->InvalidDraw();
- RERAISE;
- ENDTRY
-
- // Done mangling the text. Force update.
- display->EnableDrawing();
- display->InvalidDraw();
-
- {
- // Force everthing to redraw.
- ODRect bounds;
- Rect viewRect;
-
- _fTextension->GetViewRect(&viewRect);
- IntToFixedRect(viewRect, bounds);
-
- TempODShape invalidArea = frame->CreateShape(ev);
- invalidArea->SetRectangle(ev, &bounds);
- facet->Invalidate(ev, invalidArea, kODNULL);
- }
-
- somSelf->AdjustScrollbars(ev, frame);
-
- if ( textensionInactive )
- _fTextension->Activate(kODFalse);
- }
-
- // If the drag didn't originate with us, we clean up the temporary
- // drag structure here.
-
- if ( _fDragData->originator == kODNULL )
- {
- ODDeleteObject(_fDragData);
- _fDragData = kODNULL;
- }
-
- SOM_CATCH_ALL
-
- result = kODDropFail;
-
- // If the drag didn't originate with us, we clean up the temporary
- // drag structure here.
-
- if ( _fDragData->originator == kODNULL )
- {
- ODDeleteObject(_fDragData);
- _fDragData = kODNULL;
- }
-
- SOM_ENDTRY
-
- return result;
- }
-
-
-
- //==============================================================================
- #pragma mark • Undo •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: UndoAction
- // Origin: ODPart
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK TextEditor__UndoAction
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODActionData* actionState
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","UndoAction");
-
- SOM_TRY
-
- THROW(kODErrNotImplemented);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: RedoAction
- // Origin: ODPart
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK TextEditor__RedoAction
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODActionData* actionState
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","RedoAction");
-
- SOM_TRY
-
- THROW(kODErrNotImplemented);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DisposeActionState
- // Origin: ODPart
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK TextEditor__DisposeActionState
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODActionData* actionState,
- ODDoneState doneState
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DisposeActionState");
-
- SOM_TRY
-
- THROW(kODErrNotImplemented);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: WriteActionState
- // Origin: ODPart
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK TextEditor__WriteActionState
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODActionData* actionState,
- ODStorageUnitView* storageUnitView
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","WriteActionState");
-
- SOM_TRY
-
- THROW(kODErrNotImplemented);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: ReadActionState
- // Origin: ODPart
- //------------------------------------------------------------------------------
- SOM_Scope ODActionData
- SOMLINK TextEditor__ReadActionState
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODStorageUnitView* storageUnitView
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","ReadActionState");
-
- ODActionData data;
- data._maximum = 0;
- data._length = 0;
- data._buffer = kODNULL;
-
- SOM_TRY
-
- THROW(kODErrNotImplemented);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return data;
- }
-
- //==============================================================================
- #pragma mark -
- //==============================================================================
-
- //==============================================================================
- #pragma mark • Event Handling •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: MakeSelectionVisible
- // Origin: TextEditor
- //
- // Description: Assure that the end of the pasted selection is in the frame.
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__MakeSelectionVisible
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","MakeSelectionVisible");
-
- SOM_TRY
-
- // Assure that the end of the selection is in the frame.
-
- if ( frame->IsRoot(ev) )
- {
- short editAction = _fTextension->GetLastEditAction();
-
- ODBoolean needAdjustScrollbars = (editAction & kScrollSelection) != 0;
- if ( editAction & kScrollSelection )
- {
- Rect visRect;
- _fTextension->GetViewRect(&visRect);
-
- TLongPoint scrollVals;
- if ( !_fTextension->IsSelectionVisible(visRect, &scrollVals) )
- {
- _fTextension->Scroll(&scrollVals);
-
- // This part, especially, should only be done if it's a root frame.
- ODFacet* facet = somSelf->GetActiveFacetForFrame(ev, frame);
- CFocus intiateDrawing(ev, facet);
- somSelf->DrawPageBounds(ev);
-
- needAdjustScrollbars = kODTrue;
- }
- }
-
- // We might need to adjust the scrollbars whenever this routine
- // is called. Textension will tell us when we need to do this.
- if ( needAdjustScrollbars )
- somSelf->AdjustScrollbars(ev, frame);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: NotDragSelection
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__NotDragSelection
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet,
- Point* where,
- ODEventData* event
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","NotDragSelection");
-
- ODBoolean notDragging = kODTrue;
-
- SOM_TRY
-
- somSelf->CalcSelectionRgn(ev, facet);
-
- if ( PtInRgn(*where, (RgnHandle) _fSelectionRgn) &&
- WaitMouseMoved(event->where) )
- {
- notDragging = kODFalse;
- }
-
- SOM_CATCH_ALL
-
- notDragging = kODTrue;
-
- SOM_ENDTRY
-
- return notDragging;
- }
-
- //------------------------------------------------------------------------------
- // Method: DoMouseEvent
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoMouseEvent
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet,
- Point* where,
- ODEventData* event
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoMouseEvent");
-
- SOM_TRY
-
- // Determine if it was a hit on one of our scroll bars.
- ODSShort partCode = 0;
- ControlHandle scrollbar = kODNULL;
- {
- WindowPtr window = facet->GetCanvas(ev)->GetQDPort(ev);
- partCode = FindControl(*where, window, &scrollbar);
-
- // Make sure it's a control that belongs to us.
- if ( scrollbar != _fVScrollbar && scrollbar != _fHScrollbar )
- partCode = 0;
- }
-
- // Handle it.
- if ( partCode > 0 )
- {
- somSelf->DoScrollDocument(ev, facet, where, partCode, scrollbar);
- }
- else if ( somSelf->NotDragSelection(ev, facet, where, event) )
- {
- // Click in document (activate if background click).
-
- if ( event->what == kODEvtBGMouseDown )
- {
- somSelf->Activate(ev, facet);
- }
- else
- {
- ODFrame* frame = facet->GetFrame(ev);
-
- ClickCommandInfo info;
- ScrollDataRec* scrollData = kODNULL;
- ClickLoopProcPtr clickLoop = kODNULL;
- TempODPtr disposer = kODNULL;
-
- if ( frame->IsRoot(ev) )
- {
- scrollData = new ScrollDataRec;
- disposer = scrollData;
-
- scrollData->vScrollbar = _fVScrollbar;
- scrollData->hScrollbar = _fHScrollbar;
- scrollData->frame = frame;
- scrollData->textension = kODNULL;
- scrollData->textEditor = somSelf;
-
- clickLoop = (ClickLoopProcPtr) &ClickLoopProc;
- }
-
- CFocus initiateDrawing(ev, facet);
-
- _fTextension->Click(*event, &info, clickLoop, (void*) scrollData);
-
- if ( frame->IsRoot(ev) )
- somSelf->DrawPageBounds(ev);
- }
- }
- else
- {
- somSelf->DoDragSelection(ev, event, facet);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoScrollDocument
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoScrollDocument
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFacet* facet,
- Point* mouse,
- ODSShort partCode,
- ControlHandle scrollbar
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoScrollDocument");
-
- SOM_TRY
-
- ODFrame* frame = facet->GetFrame(ev);
-
- if ( partCode == kControlIndicatorPart )
- {
- short vScroll = GetControlValue(_fVScrollbar);
- short hScroll = GetControlValue(_fHScrollbar);
-
- TrackControl(scrollbar, *mouse, kODNULL);
-
- vScroll -= GetControlValue(_fVScrollbar);
- hScroll -= GetControlValue(_fHScrollbar);
-
- TLongPoint scrollAmount(hScroll, vScroll);
- _fTextension->Scroll(&scrollAmount);
- }
- else
- {
- ControlActionUPP scrollProcUPP = NewControlActionProc(ScrollProc);
- ScrollDataRec* scrollData = (ScrollDataRec*) ODNewPtr(sizeof(ScrollDataRec));
-
- scrollData->vScrollbar = _fVScrollbar;
- scrollData->hScrollbar = _fHScrollbar;
- scrollData->frame = frame;
- scrollData->textension = _fTextension;
- scrollData->textEditor = somSelf;
-
- SetControlReference(scrollbar, (long) scrollData);
- // Stuff the scroll data structure into the scroll bar we are
- // working with.
-
- TrackControl(scrollbar, *mouse, scrollProcUPP);
- }
-
- if ( frame->IsRoot(ev) )
- {
- CFocus intiateDrawing(ev, facet);
- somSelf->DrawPageBounds(ev);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoDragSelection
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoDragSelection
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODEventData* event,
- ODFacet* facet
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoDragSelection");
-
- SOM_TRY
-
- TOffsetRange curSelectionRange;
- ODDropResult result = kODDropFail;
- TempODPart part = kODNULL;
- ODFrame* frame = facet->GetFrame(ev);
-
- _fTextension->GetSelectionRange(&curSelectionRange);
- // Get the selection range to written out.
-
- ODDragAndDrop* dragdrop = ODGetSession(ev, somSelf)->GetDragAndDrop(ev);
-
- dragdrop->Clear(ev);
- // Remove existing data from the drag container.
-
- ODStorageUnit* dragdropSU = dragdrop->GetContentStorageUnit(ev);
-
- somSelf->CheckAndAddProperties(ev, dragdropSU);
- // Add the properties we need to successfully externalize
- // ourselves into the destination storage unit.
-
- // Write out the part's state information.
- ODDraft* toDraft = ODGetDraft(ev, dragdropSU);
- ODDraft* fromDraft = ODGetDraft(ev, somSelf);
-
- // The clone type (cut or copy) should depend on whether the document
- // is read-only. (i.e. a read-only document must use kODCloneCopy -- a
- // r/w document must use kODCloneCut if it wants to support kODDropMove).
- ODCloneKind method = (_fReadOnlyStorage ? kODCloneCopy
- : kODCloneCut);
-
- ODDraftKey key = fromDraft->BeginClone(ev, toDraft, kODNULL, method);
-
- TRY
- somSelf->ExternalizeStateInfo(ev, dragdropSU, key, frame);
-
- // Write out the current selection.
- somSelf->ExternalizeContent(ev, dragdropSU, &curSelectionRange);
-
- fromDraft->EndClone(ev, key);
-
- CATCH_ALL
- // TextEditor: Clone to drag-and-drop container failed
- fromDraft->AbortClone(ev, key);
- RERAISE;
- ENDTRY
-
- // Create and init our drag state structure to be used by
- // DragEnter, DragWithin, DragLeave, and Drop
-
- TOffsetRange blankRange((long) -1, (long) 0);
-
- _fDragData = new DragData;
-
- _fDragData->dropPoint = blankRange;
- _fDragData->acceptable = kUndefined;
- _fDragData->originator = facet;
-
- // Move selection region into global coordinates
- Point pt = {0,0};
- {
- CFocus initiateDrawing(ev, facet);
- LocalToGlobal(&pt);
- }
-
- OffsetRgn((RgnHandle) _fSelectionRgn, pt.h, pt.v);
-
- // $$$$$ Undo support for dragging goes in here somewhere!!
-
- RgnHandle dragRgn = ODNewRgn();
-
- TRY
- CopyRgn((RgnHandle) _fSelectionRgn, dragRgn);
- InsetRgn(dragRgn, -1, -1);
- DiffRgn(dragRgn, (RgnHandle) _fSelectionRgn, dragRgn);
-
- // Create Byte Arrays for the 2 dynamic parameters
- {
- TempODByteArrayStruct dragRgnBA = CreateByteArrayStruct(&dragRgn, sizeof(RgnHandle));
- TempODByteArrayStruct eventBA = CreateByteArrayStruct(&event, sizeof(ODEventData*));
-
- ODPart* returnPart;
- result = dragdrop->StartDrag(ev, frame, kODDragImageRegionHandle, dragRgnBA,
- &returnPart, eventBA);
- part = returnPart; // Put it into our TempODPart
- }
-
- // Handle drop result.
- if ( result == kODDropMove )
- {
- // If we're dropping into our own part, we'll handle the clearing
- // of the old selection in our Drop code, so don't do it here (because
- // the selection will now be the dropped data).
- if ( !ODObjectsAreEqual(ev, _fSelf, part) )
- {
- // Remove the dragged content.
- somSelf->DoClear(ev, frame);
- }
- }
- else if ( result == kODDropFail )
- {
- CFocus initiateDrawing(ev, facet);
-
- // Restore the "old" selection if the drop failed
- _fTextension->SetSelectionRange(curSelectionRange, kODFalse, kODTrue);
- }
- CATCH_ALL
- DisposeRgn(dragRgn);
- ODDeleteObject(_fDragData);
- _fDragData = kODNULL;
- RERAISE;
- ENDTRY
-
- DisposeRgn(dragRgn);
- ODDeleteObject(_fDragData);
- _fDragData = kODNULL;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoCut
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoCut
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoCut");
-
- SOM_TRY
-
- // $$$$$ should be using kODCloneCut and our own code...
-
- somSelf->DoCopy(ev, frame);
- somSelf->DoClear(ev, frame);
-
- somSelf->MakeSelectionVisible(ev, frame);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoCopy
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoCopy
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoCopy");
-
- SOM_TRY
-
- TOffsetRange curSelectionRange;
-
- ODSession* session = ODGetSession(ev, somSelf);
-
- // Acquire clipboard focus
- session->GetArbitrator(ev)->RequestFocus(ev, gGlobals->fClipboardFocus, frame);
-
- _fTextension->GetSelectionRange(&curSelectionRange);
- // Get the selection range to written out.
-
- ODClipboard* clipboard = session->GetClipboard(ev);
-
- clipboard->Clear(ev);
- // Remove existing data from the clipboard.
-
- ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
- ODDraft* fromDraft = ODGetDraft(ev, somSelf);
- ODDraft* toDraft = ODGetDraft(ev, clipboardSU);
-
- TRY
- // Add the properties we need to successfully externalize
- // ourselves into the destination storage unit.
- somSelf->CheckAndAddProperties(ev, clipboardSU);
-
- ODDraftKey key = fromDraft->BeginClone(ev, toDraft, kODNULL, kODCloneCopy);
- TRY
- somSelf->ExternalizeStateInfo(ev, clipboardSU, key, frame);
- // Write out the part's state information.
-
- somSelf->ExternalizeContent(ev, clipboardSU, &curSelectionRange);
- // Write out the current selection.
-
- fromDraft->EndClone(ev, key);
- CATCH_ALL
- fromDraft->AbortClone(ev, key);
- RERAISE;
- ENDTRY
- CATCH_ALL
- clipboard->Clear(ev);
- RERAISE;
- ENDTRY
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- }
-
- //------------------------------------------------------------------------------
- // Method: DoPaste
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoPaste
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoPaste");
-
- SOM_TRY
-
- // $$$$$ UNDO: capture current selection
-
- // Get the selection range.
- TOffsetRange curSelectionRange;
- _fTextension->GetSelectionRange(&curSelectionRange);
-
- ODSession* session = ODGetSession(ev, frame);
-
- if ( session->GetArbitrator(ev)->RequestFocus(ev, gGlobals->fClipboardFocus,
- frame) )
- {
- ODULong bytesRead = 0;
- ODClipboard* clipboard = session->GetClipboard(ev);
- ODFacet* facet = somSelf->GetActiveFacetForFrame(ev, frame);
-
- CFocus intiateDrawing(ev, facet);
-
- // Read in the clipboard data replacing the current selection.
- bytesRead = somSelf->InternalizeContent(ev, clipboard->GetContentStorageUnit(ev),
- &curSelectionRange);
-
- session->GetArbitrator(ev)->RelinquishFocus(ev, gGlobals->fClipboardFocus,
- frame);
-
- if ( bytesRead > 0 )
- {
- somSelf->HandleChange(ev);
- somSelf->MakeSelectionVisible(ev, frame);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoPasteAs
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoPasteAs
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoPasteAs");
-
- SOM_TRY
-
- // $$$$$ UNDO: capture current selection
-
- // Get the selection range.
- TOffsetRange curSelectionRange;
- _fTextension->GetSelectionRange(&curSelectionRange);
-
- ODSession* session = ODGetSession(ev, frame);
-
- if ( session->GetArbitrator(ev)->RequestFocus(ev, gGlobals->fClipboardFocus, frame) )
- {
- ODULong bytesRead = 0;
- ODClipboard* clipboard = session->GetClipboard(ev);
- ODFacet* facet = somSelf->GetActiveFacetForFrame(ev, frame);
- ODPasteAsResult result;
-
- CFocus intiateDrawing(ev, facet);
-
- if ( clipboard->ShowPasteAsDialog(ev, kODFalse, kODPasteAsMergeOnly,
- facet, gGlobals->fFrameView, &result) )
- {
- ODDraft* draft = ODGetDraft(ev, frame);
- ODStorageUnit* contentSU = clipboard->GetContentStorageUnit(ev);
-
- ODStorageUnit* tempSU = kODNULL;
- ODVolatile(tempSU);
-
- TRY
- // Create a temporary buffer (su) for the translated data.
- tempSU = draft->CreateStorageUnit(ev);
-
- // Translate the data.
- TranslateData(ev, contentSU, tempSU, result.translateKind, result.selectedKind);
-
- // Read in the clipboard data replacing the current selection.
- bytesRead = somSelf->InternalizeContent(ev, tempSU, &curSelectionRange);
-
- if ( tempSU )
- draft->RemoveStorageUnit(ev, tempSU);
-
- CATCH_ALL
- if ( tempSU )
- draft->RemoveStorageUnit(ev, tempSU);
-
- somSelf->DoDialogBox(ev, frame, kErrorBoxID, kErrTranslationFailed);
-
- // An error occurred, so don't dirty the document.
- bytesRead = 0;
- ENDTRY
- }
-
- session->GetArbitrator(ev)->RelinquishFocus(ev, gGlobals->fClipboardFocus, frame);
-
- if ( bytesRead > 0 )
- {
- somSelf->HandleChange(ev);
- somSelf->MakeSelectionVisible(ev, frame);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoClear
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoClear
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoClear");
-
- SOM_TRY
-
- // $$$$$ UNDO: capture current selection
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- CFocus initiateDrawing(ev, frameInfo->GetActiveFacet());
-
- _fTextension->Clear();
-
- somSelf->MakeSelectionVisible(ev, frame);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoSelectAll
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoSelectAll
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoSelectAll");
-
- SOM_TRY
-
- TOffsetRange curSelectionRange(0, _fTextension->CountCharsBytes());
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- CFocus initiateDrawing(ev, frameInfo->GetActiveFacet());
-
- _fTextension->SetSelectionRange(curSelectionRange, kODTrue, kODTrue);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoPageSetup
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoPageSetup
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoPageSetup");
- }
-
- //------------------------------------------------------------------------------
- // Method: DoPrint
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoPrint
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoPrint");
- }
-
- //------------------------------------------------------------------------------
- // Method: DoUndo
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoUndo
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame,
- ODBoolean undo
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoUndo");
-
- SOM_TRY
-
- somSelf->MakeSelectionVisible(ev, frame);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoPreferences
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoPreferences
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoPreferences");
-
- SOM_TRY
-
- ModalPreferencesDialog(ev, frame);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: ShowHideRuler
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__ShowHideRuler
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","ShowHideRuler");
- }
-
- //------------------------------------------------------------------------------
- // Method: DoSettings
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoSettings
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoSettings");
-
- SOM_TRY
- Rect margins = _fPageMargins;
- ODUShort alignment = _fTextAlignment;
- ODBoolean changed = kODFalse;
-
- ModalSettingsDialog(ev, frame, &margins, &alignment);
-
- if ( margins.top != _fPageMargins.top ||
- margins.left != _fPageMargins.left ||
- margins.bottom != _fPageMargins.bottom ||
- margins.right != _fPageMargins.right )
- {
- _fPageMargins = margins;
-
- somSelf->CalcTextBounds(ev, frame);
- changed = kODTrue;
- }
-
- if ( alignment != _fTextAlignment )
- {
- _fTextAlignment = alignment;
-
- char just;
-
- switch ( alignment )
- {
- case left: just = kLeftJust; break;
- case center: just = kCenterJust; break;
- case right: just = kRightJust; break;
- case fulljustification: just = kFullJust; break;
- default:
- just = kLeftJust;
- }
-
- AttrObjModifier runModifier(kJustAttr, &just, 0L);
- TOffsetRange curSelectionRange(0, _fTextension->CountCharsBytes());
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- CFocus initiateDrawing(ev, frameInfo->GetActiveFacet());
-
- _fTextension->UpdateRangeRulers(curSelectionRange, runModifier);
-
- changed = kODTrue;
- }
-
- if ( changed )
- somSelf->HandleChange(ev);
-
- somSelf->AdjustScrollbars(ev, frame);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //------------------------------------------------------------------------------
- // Method: RealFontSizeMenu
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__RealFontSizeMenu
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODUShort fontNum
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","RealFontSizeMenu");
-
- SOM_TRY
-
- MenuHandle sizeMenu = (MenuHandle) gGlobals->fMenuBar->GetMenu(ev, kSizeMenuID);
-
- SetItemStyle(sizeMenu, 1, (RealFont(fontNum, 9) ? outline : normal));
- SetItemStyle(sizeMenu, 2, (RealFont(fontNum,10) ? outline : normal));
- SetItemStyle(sizeMenu, 3, (RealFont(fontNum,12) ? outline : normal));
- SetItemStyle(sizeMenu, 4, (RealFont(fontNum,14) ? outline : normal));
- SetItemStyle(sizeMenu, 5, (RealFont(fontNum,18) ? outline : normal));
- SetItemStyle(sizeMenu, 6, (RealFont(fontNum,24) ? outline : normal));
- SetItemStyle(sizeMenu, 7, (RealFont(fontNum,36) ? outline : normal));
- SetItemStyle(sizeMenu, 8, (RealFont(fontNum,48) ? outline : normal));
- SetItemStyle(sizeMenu, 9, (RealFont(fontNum,72) ? outline : normal));
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //------------------------------------------------------------------------------
- // Method: DoTextStyling
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean
- SOMLINK TextEditor__DoTextStyling
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame,
- ODID command
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoTextStyling");
-
- SOM_TRY
-
- AttrId attrModified;
- void* attrData;
- ODSLong attrInfo = 0;
-
- if ( command >= kBaseFontSizeCmdID && command <= kBaseFontSizeCmdID + 999 )
- {
- // Change Font Size
-
- ODSShort fontSize = command - kBaseFontSizeCmdID;
-
- if ( command == kOtherFontSizeCmdID )
- {
- // Get the current font size of the selected text.
- ODSLong value;
- if ( _fTextension->GetContinuousRun()->GetAttributeValue(kFontSizeAttr, &value) )
- fontSize = (value >> 16);
- else
- fontSize = -1;
-
- somSelf->DoOtherFontSize(ev, frame, &fontSize);
-
- if ( fontSize == -1 ) return kODTrue;
- // user canceled the "other size" dialog
- }
-
- attrModified = kFontSizeAttr;
- attrData = (void*) &fontSize;
- }
- else if ( command >= kBaseFontStyleCmdID && command <= kBaseFontStyleCmdID + 999 )
- {
- // Change Font Style
-
- ODSLong fontStyle = (ODSLong)(command - kBaseFontStyleCmdID);
-
- attrModified = kFaceAttr;
- attrData = (void*) &fontStyle;
- attrInfo = kToggleFace;
- }
- else
- {
- // Change Font (maybe)
-
- ODUShort fontNum = command - kBaseFontCmdID;
-
- attrModified = kFontAttr;
- attrData = (void*) &fontNum;
-
- // Make sure
- Str255 fontName;
- GetFontName(fontNum,fontName);
- if ( *fontName == 0 )
- return kODFalse;
- }
-
- AttrObjModifier runModifier(attrModified, attrData, attrInfo);
- TOffsetRange curSelectionRange;
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- CFocus initiateDrawing(ev, frameInfo->GetActiveFacet());
-
- _fTextension->GetSelectionRange(&curSelectionRange);
- _fTextension->UpdateRangeRuns(curSelectionRange, runModifier);
-
- somSelf->AdjustScrollbars(ev, frame);
-
- somSelf->HandleChange(ev);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // Method: DoOtherFontSize
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoOtherFontSize
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame,
- ODSShort* fontSize
- )
- {
- SOM_TRY
-
- const ODUShort kSizeField = 3;
- const ODUShort kDefaultButtonHighlight = 6;
-
- short iType;
- Handle iHandle;
- Rect iRect;
- short itemHit;
- Str255 strValue;
- long value;
-
- ODSession* session = ODGetSession(ev, frame);
-
- if ( session->GetArbitrator(ev)->RequestFocus(ev, gGlobals->fModalFocus, frame) )
- {
- CUsingLibraryResources res;
-
- session->GetWindowState(ev)->DeactivateFrontWindows(ev);
- // Dim the frontmost document window.
-
- DialogPtr dialog = GetNewDialog(kOtherSizeDialogID, kODNULL, (WindowPtr)-1L);
-
- // Set dialog font and other std things.
- SetDialogDefaults(dialog, kDialogFontInfoID, kOtherFontIndex);
-
- // Install a default drawing routine for the "default" button highlighting.
- GetDialogItem(dialog, kDefaultButtonHighlight, &iType, &iHandle, &iRect);
- SetDialogItem(dialog, kDefaultButtonHighlight, iType, (Handle)GetODOutlineDefaultButtonDrawProc(), &iRect);
-
- // Stuff a default value into the size field.
- GetDialogItem(dialog, kSizeField, &iType, &iHandle, &iRect);
- {
- Str255 startSizeStr = "\p";
- if (*fontSize > 0)
- NumToString(*fontSize, startSizeStr);
- SetDialogItemText(iHandle, startSizeStr);
- }
- SelectDialogItemText(dialog, kSizeField, 0, 32767);
-
- ShowWindow(dialog);
-
- // Prepare a filter proc which only allows numbers [0-9] to be entered.
- ModalFilterUPP otherDialogProc = NewModalFilterProc(OtherDialogFilter);
-
- // Handle the dialog.
- do
- {
- ModalDialog(otherDialogProc, &itemHit);
- }
- while ( itemHit != ok && itemHit != cancel );
-
- // Check the result.
- if ( itemHit == ok )
- {
- GetDialogItemText(iHandle, strValue);
- if (strValue[0] == 0)
- {
- *fontSize = -1;
- }
- else
- {
- StringToNum(strValue, &value);
-
- if ( value > 512 )
- *fontSize = 512;
- else if ( value <= 0 )
- *fontSize = -1;
- else
- *fontSize = (ODSShort) value;
- }
- }
- else
- {
- *fontSize = -1;
- }
-
- DisposeDialog(dialog);
- DisposeRoutineDescriptor(otherDialogProc);
-
- session->GetArbitrator(ev)->RelinquishFocus(ev, gGlobals->fModalFocus, frame);
- // Inform the Arbitrator that we no longer require the Modal focus.
-
- session->GetWindowState(ev)->ActivateFrontWindows(ev);
- // Hilite the frontmost document window.
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoIdle
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoIdle
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoIdle");
-
- SOM_TRY
-
- CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev);
- ODFacet* facet = frameInfo->GetActiveFacet();
-
- if ( facet )
- {
- // Focus drawing environment so caret is drawn in the right place.
- CFocus initiateDrawing(ev, facet);
-
- // Idle Textension.
- _fTextension->Idle();
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // Method: DoAboutBox
- // Origin: TextEditor
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoAboutBox
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoAboutBox");
-
- SOM_TRY
-
- somSelf->DoDialogBox(ev, frame, kAboutDialogID, 0);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //------------------------------------------------------------------------------
- // Method: DoDialogBox
- // Origin: TextEditor
- //
- // Description: This method is called by the part when a dialog needs to be
- // displayed (e.g. the About Box). If a valid error number is passed
- // in, an error dialog will be displayed.
- //------------------------------------------------------------------------------
-
- SOM_Scope void
- SOMLINK TextEditor__DoDialogBox
- (
- SampleCode_TextEditor* somSelf,
- Environment* ev,
- ODFrame* frame,
- ODSShort dialogID,
- ODUShort errorNumber
- )
- {
- SampleCode_TextEditorData *somThis = SampleCode_TextEditorGetData(somSelf);
- SOMMethodDebug("TextEditor","DoDialogBox");
-
- SOM_TRY
-
- ODFrame* focusFrame = frame;
- ODSession* session = ODGetSession(ev, somSelf);
-
- // If the calling method does not have a frame available to it, we need to
- // locate a frame to use for requesting the modal focus. Find the first valid
- // frame in our display frames list.
- if ( focusFrame == kODNULL )
- {
- CListIterator fiter(_fDisplayFrames);
- for ( CFrameProxy* proxy = (CFrameProxy*) fiter.First();
- fiter.IsNotComplete(); proxy = (CFrameProxy*) fiter.Next() )
- {
- if ( proxy->FrameIsLoaded(ev) )
- focusFrame = proxy->GetFrame(ev);
- if ( focusFrame ) break;
- }
- }
-
- // Our dialog boxes are modal so we must request the Modal focus to prevent
- // multiple modal dialogs being displayed simultaneously.
-
- if ( session->GetArbitrator(ev)->RequestFocus(ev, gGlobals->fModalFocus, focusFrame) )
- {
- DialogPtr dialog;
- ODSShort itemHit;
-
- // Dim the frontmost document window.
- session->GetWindowState(ev)->DeactivateFrontWindows(ev);
-
- CUsingLibraryResources res;
-
- dialog = GetNewDialog(dialogID, kODNULL, (WindowPtr) -1L);
-
- if ( dialog )
- {
- if ( errorNumber > 0 )
- {
- Handle iHandle;
- Rect iRect;
- short iType;
- Str255 errStr;
-
- GetIndString(errStr, kErrorStringsID, errorNumber);
- GetDialogItem(dialog, kErrStrFieldID, &iType, &iHandle, &iRect);
- SetDialogItemText(iHandle, errStr);
-
- // We don't need the cancel button for an error dialog.
- HideDialogItem(dialog, cancel);
-
- SetDialogDefaultItem(dialog, ok);
- }
-
- ShowWindow(dialog);
- SetCursor(&ODQDGlobals.arrow);
- ModalDialog(kODNULL, &itemHit);
- DisposeDialog(dialog);
- }
- else
- {
- // Could not load dialog box dialog... something is amiss.
- SysBeep(2);
- }
-
- // Hilite the frontmost document window.
- session->GetWindowState(ev)->ActivateFrontWindows(ev);
-
- // Inform the Arbitrator that we no longer require the Modal focus.
- session->GetArbitrator(ev)->RelinquishFocus(ev, gGlobals->fModalFocus, focusFrame);
- }
- else
- {
- // If we can't get the modal focus, then another modal dialog is
- // already being displayed.
- SysBeep(2);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-